# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=gnu-efi
pkgver=3.0.14
pkgrel=1
pkgdesc="Develop EFI applications using the GNU toolchain and the EFI development environment"
arch=('x86_64')
url="https://sourceforge.net/projects/gnu-efi/"
license=('BSD')
conflicts=('gnu-efi-libs')
provides=('gnu-efi-libs')
replaces=('gnu-efi-libs')
source=("https://download.sourceforge.net/${pkgname}/${pkgname}-${pkgver}.tar.bz2"
        "${pkgname}-3.0.12-ldflags.patch")
sha512sums=('37420ba3804e8547451a7b143a689ceb6af0557234fa7801efdeba3c2fc581a5354fe34cbaacb338d7b394d913e7274098ebf07026b7c1d50b2236d7f86c470c'
            '7fd1c8d09ff870c33ae62887b657a7367f85a07f6709d33471ca13117a08e755853fd1e99db492d1db47444b95ae871078c4a913ed70aa7236e49349046e06b6')
b2sums=('c7f9127d3bb7e5e2bc52f5fc7be3376ddc5076b262e5db5a30a997cf10bf10288da63ded64d11327fad09190a803ce26e82b32aea2d8525ee0d1e1a23ebadff2'
        'c1633240ee6363c1df2ae5d7aab5a76a8fe93fd86a2c9a4973b8b30273e1512914c67c88483d0880cfca00df38b3b62fe9e1cd173b139b622ee83f0db835320f')

prepare() {
  cd "$pkgname-$pkgver"
  # -Werror, not even once
  sed -e 's/-Werror//g' -i Make.defaults
  # insert LDFLFAGS into custom linker for apps
  patch -Np1 -i "../${pkgname}-3.0.12-ldflags.patch"
}

build() {
  cd "$pkgname-$pkgver"
  make
  make -C lib
  make -C gnuefi
  make -C inc
  # unset LDFLAGS for custom linker used in apps, as we have patched our
  # LDFLAGS in manually in prepare()
  LDFLAGS=""
  make -C apps
}

package() {
  cd "$pkgname-$pkgver"
  make INSTALLROOT="$pkgdir/" PREFIX='/usr' install
  install -vDm 644 apps/*.efi -t "${pkgdir}/usr/share/${pkgname}/apps/$CARCH"
  install -vDm 644 README.efilib -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -vDm 644 {ChangeLog,README.{gnuefi,git,elilo}} \
    -t "${pkgdir}/usr/share/doc/${pkgname}"
}
